package com.example.testall;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xxg
 */
@Slf4j
public class ContacTest {
    @Test
    public void to1() {
        String url = "http://api.hb-sino.com/contact/plug/getContactInfo";
        Map<String, String> param = new HashMap<>();
        param.put("keyId", "190b07a3bd414d6d8a73fc83103a12b7");
        param.put("startRow", "0");
        Map<String, String> headerMap = new HashMap<>();
        headerMap.put("token", "6_ca8d2455-926c-46dc-8fb9-a23e1d8e62bc");
        JSONObject jsonObject = HttpRequestUtils.httpPost(url, param, headerMap);
        final JSONObject data1 = jsonObject.getJSONObject("data");
        final int total = data1.getIntValue("total");
        log.info("--" + total);
        int n=1;
        int count=data1.getJSONArray("list").size();
        while (true) {
            param.remove("startRow");
            JSONObject jsonObject2 = HttpRequestUtils.httpPost(url, param, headerMap);
            if (jsonObject2.containsKey("data") && jsonObject2.get("data") != null) {

                JSONObject data = jsonObject2.getJSONObject("data");
                if (data.get("list") != null) {
                    int listSize = data.getJSONArray("list").size();
                    if (listSize < 1) {
                        log.info("end----------------"+n);
                        log.info("count----------------"+count);
                        break;
                    } else if (1000 != listSize) {
                        log.info("---" + listSize);
                    }
                    n++;
                    count+=listSize;
                }
            } else {
                break;
            }
        }
    }
}
